package com.studycloud.tjshareuniversity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.tojoy.shop.TJShopEngine;

public class ItemActivity extends AppCompatActivity {

    private static final String INTENT_TYPE = "type";

    public static void launch(Context context, int type) {
        Intent intent = new Intent(context, ItemActivity.class);
        intent.putExtra(INTENT_TYPE, type);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item);
        int type = getIntent().getIntExtra(INTENT_TYPE, 0);
        EditText editText = findViewById(R.id.edit_code_view);
        TextView login_view = findViewById(R.id.btn_view);
        if (type == 2) {
            editText.setHint("请输入订单号");
            login_view.setText("微信支付");
        }
        login_view.setOnClickListener(v -> {
            String code = editText.getText().toString();
            if (TextUtils.isEmpty(code)) {
                Toast.makeText(ItemActivity.this, type == 1 ? "请输入场景ID" : "请输入订单号", Toast.LENGTH_SHORT).show();
                return;
            }
            if (type == 1) {
                TJShopEngine.skipGoodList(ItemActivity.this, code);
            } else if (type == 2) {
                TJShopEngine.pay(ItemActivity.this, code, true);
            }

        });
    }
}